package com.hzhr.iot.cqgas.ds.controller;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.cqgas.ds.dao.device.custom.DeviceDao;
import com.hzhr.iot.cqgas.ds.dao.device.example.DevImplRecordDao;
import com.hzhr.iot.cqgas.ds.dao.user.custom.UserCustomDao;
import com.hzhr.iot.cqgas.ds.entity.device.DevImplRecordEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
public class ImplResourceController {
    @Autowired
    DevImplRecordDao devImplRecordDao;
    @Autowired
    UserCustomDao userCustomDao;
    @Autowired
    DeviceDao deviceDao;

    @RequestMapping(value = "/syncImplResourceInfo")
    public void syncImplResourceImg() {
        List<DevImplRecordEntity> devImplRecordEntities = devImplRecordDao.selectByExample(null);
        for (DevImplRecordEntity devImplRecordEntity :
        devImplRecordEntities) {
            boolean updateflag = false;
            //关联设备
            String iotDeviceCode = devImplRecordEntity.getIotDeviceCode();
            if (iotDeviceCode != null) {
                Integer iotDeviceId = deviceDao.select10(iotDeviceCode);
                if ((iotDeviceId == null && devImplRecordEntity.getIotDeviceId() != null) || (iotDeviceId != null && !iotDeviceId.equals(devImplRecordEntity.getIotDeviceId()))) {
                    devImplRecordEntity.setIotDeviceId(iotDeviceId);
                    updateflag = true;
                }

            }
            String collectDeviceCode = devImplRecordEntity.getCollectDeviceCode();
            if (collectDeviceCode != null) {
                Integer collectDeviceId = deviceDao.select11(collectDeviceCode);
                if ((collectDeviceId == null && devImplRecordEntity.getCollectDeviceId() != null) || (collectDeviceId != null && !collectDeviceId.equals(devImplRecordEntity.getCollectDeviceId()))) {
                    devImplRecordEntity.setCollectDeviceId(collectDeviceId);
                    updateflag = true;
                }
            }

            if (updateflag) devImplRecordDao.updateByPrimaryKey(devImplRecordEntity);
        }
    }
}
